<template>
  <div class="body" :class="{active}">
    <!-- 积分商城 -->
    <!-- <div class="header">
      <div>
        <img @click="returnGo" src="../assets/homeimg/滑动左.png" />
        <span>积分商城</span>
      </div>
    </div> -->
    <!-- <Header></Header> -->
    <div class="main">
      <div class="main-c">
        <div class="main-top">
          <div class="integral">
            <span class="last">剩余积分</span>
            <span class="num">{{integral}}</span>
          </div>
          <div class="change" @click="record">
            <span class="last">兑换记录</span>
            <img class="image" src="../assets/homeimg/jilu.png" alt />
          </div>
        </div>
        <div class="center">
          <img class="center-t" src="../assets/homeimg/标题.png" alt="">
          <ul class="list">
            <!-- :to="`/shopInfo/${item.id}`" -->
            <router-link tag="li" class="item" v-for="item in list" :key="item.id" :to="{path:'/shopInfo',query:{id:item.id}}">
              <img :src="item.image" alt class="left-img" />
              <div class="right">
                <div class="title">{{item.title}}</div>
                <div class="text">
                  <span class="text-a">{{item.score}}积分</span>
                  <span class="text-b">¥{{item.price}}</span>
                </div>
                <div class="btn">立即换购</div>
              </div>
            </router-link>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import Header from "@/components/header";
import {
		Toast
  } from "vant";
import integralApi from '@/api/integral'
export default {
  data() {
    return {
      integral: "",
      list: [],
      active:false,
    };
  },
  components: {
    // Header
  },
  beforeDestroy: function() {
    // var arr = []
    // if (document.getElementsByClassName("page1")[0])
    //   arr = document.getElementsByClassName("page1")[0].className.split(' ')
    //   arr[0] = "page";
    //   console.log(arr)
    //   document.getElementsByClassName("page1")[0].className = arr.join(' ');
  },
  mounted() {
    // var arr = []
    // if (document.getElementsByClassName("page")[0]) {
    //   arr = document.getElementsByClassName("page")[0].className.split(' ')
    //   arr[0] = "page1"
    //   document.getElementsByClassName("page")[0].className = arr.join(' ');
    // }
  },
  created() {
    
    this.getMyscore();
    this.getShopList();
  },
  methods: {
    async getMyscore(){
      await this.$http.post('/api/score/myScore').then(res => {
        // console.log(res)
        this.integral = res.data.score;
      })
    },
    getShopList(){
       integralApi.shopList().then(res=>{
        //  console.log(res)
         this.list = res.data.data;
        //  console.log(this.list)
       })
    },
    returnGo() {
      this.$router.go(-1);
    },
    record(){
      this.$router.push('/record')
    }
  }
};
</script>

<style scoped lang="scss">
.body {
  color: #333333;
  // height: 100%;
  display: flex;
  flex-direction: column;
  // background: rgba(250, 250, 250, 1);
  background-size: 100% 100%;
  position: relative;
  // padding-top: calc(11.7333vw + 0px);
  // box-sizing: border-box;
  // &.active{
  //   padding-top: calc(11.7333vw + 30px);
  // }
}
.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  text-align: center;
  height: 2.75rem;
  line-height: 2.75rem;
  padding-top: 1.25rem;
  background: #fff;
  // line-height: 3.125rem;
  // position: relative;
  border-bottom: 1px solid rgba(220, 220, 220, 1);
  color: #333333;
  font-size: 1.25rem;
  text-align: center;
  img {
	position: absolute;
	bottom: 0.75rem;
	left: 0.9375rem;
    width: 0.625rem;
    height: 1.125rem;
  }
}
.main {
  width: 100%;
  // background: #fff;
  // margin-top:calc(11.7333vw + 3vw) ;
  
  .main-c {
    width: 92vw;
    margin: 3vw auto;
    .main-top {
      width: 100%;
      height: 3.75rem;
      margin: 0 auto;
      display: flex;
      justify-content: space-between;
      margin-top: 1.25rem;
      .integral {
        width: 39.466vw;
        height: 3.2rem;
        background: rgba(255, 208, 65, 1);
        border-radius: 0.375rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 2.66vw;
        box-sizing: border-box;
        .num {
          font-size: 0.9375rem;
          font-weight: bold;
          color: rgba(119, 84, 254, 1);
        }
      }
      .last {
        font-size: 1.125rem;
        color: rgba(255, 255, 255, 1);
      }
      .change {
        width: 39.466vw;
        height: 3.2rem;
        background: rgba(252, 120, 115, 1);
        border-radius: 0.375rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 2.66vw;
        box-sizing: border-box;
        .image {
          width: 1.1875rem;
          height: 1.5rem;
        }
      }
    }
    .center {
      width: 100%;
      margin: 0 auto;
      margin-top: 1.25rem;
      .center-t{
        display: block;
        width: 12.5rem;
        height: 1.0625rem;
        margin: 0 auto;
      }
      .center-s {
        width: 100%;
        margin: 0 auto;
        text-align: center;
        font-size: 1.125rem;
        color: rgba(51, 51, 51, 1);
        // line-height: 70px;
      }
      .list {
        list-style: none;
        .item {
          width: 100%;
          height: 6.375rem;
          background: rgba(255, 255, 255, 1);
          border-radius: 0.3125rem;
          margin: 0 auto;
          margin-top: 1.875rem;
          display: flex;
          .left-img {
            width: 6.25rem;
            height: 100%;
            border-radius: 0.3125rem;
            margin-left: 0.625rem;
          }
          .right {
            margin-left: 15px;
            .title {
              font-size: 0.9375rem;
              font-weight: bold;
              color: rgba(51, 51, 51, 1);
              display: block;
              margin-top: 0.625rem;
            }
            .text {
              display: flex;
              .text-a {
                font-size: 0.9375rem;
                font-weight: 500;
                color: rgba(255, 38, 79, 1);
                line-height: 2.1875rem;
              }
              .text-b {
                font-size: 0.625rem;
                font-weight: 500;
                text-decoration: line-through;
                color: rgba(153, 153, 153, 1);
                line-height: 2.1875rem;
                margin-left: 0.625rem;
              }
            }
            .btn {
              width: 5.625rem;
              height: 1.5rem;
              background: linear-gradient(
                173deg,
                rgba(255, 176, 7, 1),
                rgba(255, 207, 63, 1)
              );
              border-radius: 0.75rem;
              text-align: center;
              font-size: .75rem;
              font-weight: normal;
              color: rgba(255, 255, 255, 1);
              line-height:1.375rem;
            }
          }
        }
      }
    }
  }
}
</style>
